package com.yugu.park.system.controller;

import java.util.Arrays;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.Api;
import com.yugu.park.system.entity.SysDictDataEntity;
import com.yugu.park.system.service.SysDictDataService;
import com.yugu.util.ResponseUtil;
import com.yugu.util.SearchPage;
import com.github.pagehelper.PageInfo;

/**
 * 字典数据表
 *
 * @author guxf
 * @email sjzyug@163.com
 * @date 2023-08-22 08:57:15
 */
@Api(tags = {"字典数据表"})
@RestController
@RequestMapping("system/sysdictdata")
public class SysDictDataController {
    @Autowired
    private SysDictDataService service;

    /**
     * 列表
     */

    @ApiOperation(value="分页查询", notes="分页查询")
    @RequestMapping(value = "/page", method = RequestMethod.POST)
    public ResponseUtil.Result<PageInfo<SysDictDataEntity>> page (@RequestBody SearchPage<SysDictDataEntity> search){
        PageInfo<SysDictDataEntity> page = service.page(search);
        return ResponseUtil.addSuccess(page);
    }
	@ApiOperation(value="查看详情", notes="查看详情")
    @GetMapping("/{id}")
    public ResponseUtil.Result<SysDictDataEntity> info(@PathVariable("id") String id){
		SysDictDataEntity sysDictData = service.getById(id);
        return ResponseUtil.addSuccess(sysDictData);
    }
    @ApiOperation(value="新增或修改", notes="新增或修改")
    @RequestMapping(value="/addOrUpdate", method= RequestMethod.POST)
    public ResponseUtil.Result<Boolean> save(@RequestBody SysDictDataEntity sysDictData){
		service.addOrUpdate(sysDictData);
         return ResponseUtil.addSuccess(true);
    }
    @ApiOperation(value="批量删除", notes="批量删除")
    @RequestMapping(value="/{id}", method = RequestMethod.DELETE)
    public ResponseUtil.Result<Boolean> delete(@PathVariable("id") String id){
    	service.removeByIds(Arrays.asList(id.split(",")));
        return ResponseUtil.addSuccess(true);
    }
    
    @ApiOperation(value="根据typeId查询", notes="根据typeId查询")
    @GetMapping("/getByTypeId/{typeId}")
    public ResponseUtil.Result<List<SysDictDataEntity>> getByTypeId(@PathVariable("typeId") String typeId){
		List<SysDictDataEntity> sysDictData = service.getByTypeId(typeId);
        return ResponseUtil.addSuccess(sysDictData);
    }

}
